package com.japher.hackson.activity;

import android.app.Activity;
import android.os.Bundle;
import android.widget.ImageView;
import android.widget.TextView;

import com.baidu.common.async_http.IResponseListener;
import com.baidu.common.json.JsonSerializer;
import com.baidu.common.utils.TimeUtils;
import com.baidu.common.utils.Tools;
import com.baidu.common.views.LoadingDialog;
import com.japher.hackson.R;
import com.japher.hackson.document.CommentItem;
import com.japher.hackson.document.DetailInfo;
import com.japher.hackson.requests.LoadDetailRequest;
import com.japher.hackson.response.BaseResponse;

public class DetailActivity extends Activity{

    private LoadingDialog mLoadingView;
    private TextView mUserComment;
    private ImageView mUserImage;
    private TextView mTime;
    private CommentItem externalItem;
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_detail);
        
        mLoadingView = new LoadingDialog(this, false, null);
        mLoadingView.setMessage("正在加载数据...");
        
        mUserComment = (TextView)findViewById(R.id.user_comment);
        mUserImage = (ImageView)findViewById(R.id.user_img);
        mTime = (TextView)findViewById(R.id.user_time);
        
        String json = getIntent().getStringExtra("data");
        if(!Tools.isEmpty(json))
        {
            externalItem = JsonSerializer.getInstance().deserialize(json,CommentItem.class);
            mUserComment.setText(externalItem.getBody());
            mTime.setText(TimeUtils.getDateTile(externalItem.getCreatedAt()));
        }
        else{
            finish();
            return;
        }
        
        loadRemote(externalItem.get_id());
    }
    
    private DetailInfo mDetailInfo;
    
    private void loadRemote(String id){
        
        mLoadingView.show();
        
        LoadDetailRequest request = new LoadDetailRequest(id);
        request.StartRequest(new IResponseListener() {
            @Override
            public void onRequestComplete(BaseResponse response) {
                
            }
        });
        
    }
    
    private void setup(DetailInfo   info){
        
    }
    
}
